from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from tortoise.contrib.fastapi import register_tortoise
from config import TORTOISE_ORM
from apps.init.urls import init
from apps.chart.urls import chart


app = FastAPI(debug=True)  # 生产环境debug记得关

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许所有来源
    allow_credentials=True,
    allow_methods=["*"],  # 允许所有方法
    allow_headers=["*"],  # 允许所有头部
)

# app.mount("/statics", StaticFiles(directory="statics"))
register_tortoise(
    app,
    config=TORTOISE_ORM,
    generate_schemas=False
)

app.include_router(init, prefix="/init", tags=["InitAPi"])
app.include_router(chart, prefix="/chart", tags=["ChartAPi"])


if __name__ == '__main__':
    uvicorn.run("main:app", host="0.0.0.0", port=3000,
                reload=True, reload_dirs={"apps"})
